﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using VIBlend.WPF.Controls;

namespace AnonsaiWPF.CSharp.Buttons
{
    public partial class ColorPickerDemo : Window, IWindow
    {
        public ColorPickerDemo()
        {
            InitializeComponent();
            this.CustomPicker.SelectionChanged += new EventHandler(CustomPicker_SelectionChanged);
            ApplyContent();
        }

        void CustomPicker_SelectionChanged(object sender, EventArgs e)
        {
            ApplyContent();
        }

        private void ApplyContent()
        {
            Border border = new Border();
            border.Background = new SolidColorBrush(this.CustomPicker.SelectedColor);
            border.Width = 2 * this.CustomPicker.ActualWidth / 3;
            border.Height = 2 * this.CustomPicker.ActualHeight / 3;
            border.CornerRadius = new CornerRadius(3);
            border.BorderThickness = new Thickness(1.0);
            border.BorderBrush = new SolidColorBrush(Colors.LightGray);

            this.CustomPicker.ToggleButtonContent = border;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            this.picker1.Palettes.Add(CreatePanel());
            this.picker2.Palettes.Add(CreatePanel());
            this.picker3.Palettes.Add(CreatePanel());
            this.CustomPicker.Palettes.Add(CreatePanel());
        }

        private Palette CreatePanel()
        {
            Palette panel = new Palette();
            panel.Colors.Clear();
            panel.Colors.Add(Colors.Blue);
            panel.Colors.Add(Colors.Green);
            panel.Colors.Add(Colors.Red);
            panel.Colors.Add(Colors.Cyan);
            panel.Colors.Add(Colors.Yellow);
            panel.Colors.Add(Colors.White);
            panel.Colors.Add(Colors.Orange);
            panel.Colors.Add(Colors.Magenta);
            panel.Colors.Add(Colors.Purple);
            panel.Colors.Add(Colors.Brown);
            panel.HeaderText = "Custom Colors";
            return panel;
        }

        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            if (this.picker1 == null || this.picker2 == null || this.picker3 == null)
                return;

            this.picker1.ShowColorBox = true;
            this.picker2.ShowColorBox = true;
            this.picker3.ShowColorBox = true;
        }

        private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            if (this.picker1 == null || this.picker2 == null || this.picker3 == null)
                return;

            this.picker1.ShowColorBox = false;
            this.picker2.ShowColorBox = false;
            this.picker3.ShowColorBox = false;
        }

        private void CheckBox_Checked_1(object sender, RoutedEventArgs e)
        {
            if (this.picker1 == null || this.picker2 == null || this.picker3 == null)
                return;

            foreach (Palette panel in this.picker1.Palettes)
            {
                panel.HeaderVisibility = System.Windows.Visibility.Visible;
            }

            foreach (Palette panel in this.picker2.Palettes)
            {
                panel.HeaderVisibility = System.Windows.Visibility.Visible;
            }

            foreach (Palette panel in this.picker3.Palettes)
            {
                panel.HeaderVisibility = System.Windows.Visibility.Visible;
            }
        }

        private void CheckBox_Unchecked_1(object sender, RoutedEventArgs e)
        {
            if (this.picker1 == null || this.picker2 == null || this.picker3 == null)
                return;

            foreach (Palette panel in this.picker1.Palettes)
            {
                panel.HeaderVisibility = System.Windows.Visibility.Collapsed;
            }

            foreach (Palette panel in this.picker2.Palettes)
            {
                panel.HeaderVisibility = System.Windows.Visibility.Collapsed;
            }

            foreach (Palette panel in this.picker3.Palettes)
            {
                panel.HeaderVisibility = System.Windows.Visibility.Collapsed;
            }
        }

        private void CheckBox_Checked_2(object sender, RoutedEventArgs e)
        {
            if (this.picker1 == null || this.picker2 == null || this.picker3 == null)
                return;

            this.picker1.DefaultHeaderVisibility = System.Windows.Visibility.Visible;
            this.picker2.DefaultHeaderVisibility = System.Windows.Visibility.Visible;
            this.picker3.DefaultHeaderVisibility = System.Windows.Visibility.Visible;
            this.CustomPicker.DefaultHeaderVisibility = System.Windows.Visibility.Visible;
        }

        private void CheckBox_Unchecked_2(object sender, RoutedEventArgs e)
        {
            if (this.picker1 == null || this.picker2 == null || this.picker3 == null)
                return;

            this.picker1.DefaultHeaderVisibility = System.Windows.Visibility.Collapsed;
            this.picker2.DefaultHeaderVisibility = System.Windows.Visibility.Collapsed;
            this.picker3.DefaultHeaderVisibility = System.Windows.Visibility.Collapsed;
            this.CustomPicker.DefaultHeaderVisibility = System.Windows.Visibility.Collapsed;
        }

        public void DetachContent()
        {
            RemoveLogicalChild(Content);
        }

        public void SetTheme()
        {
        }

        public Grid Root
        {
            get
            {
                return this.RootVisual;
            }
        }   
    }
}
